package com.kuaifawu.lwnlawyerclient.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.kuaifawu.lwnlawyerclient.Model.LWNModel_message;
import com.kuaifawu.lwnlawyerclient.Model.LWNModel_myGoodAtList;
import com.kuaifawu.lwnlawyerclient.R;
import com.lidroid.xutils.BitmapUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangminglei on 15/2/3.
 */
public class LWNAdapter_messageCenter extends ArrayAdapter{

    private LayoutInflater mInflater;
    private List<LWNModel_message> mItems;
    private Context context_this;
    private BitmapUtils bitmapUtils=null;

    public LWNAdapter_messageCenter(Context context, int resource, List objects) {
        super(context, resource, objects);
        context_this = context;
        this.mInflater = LayoutInflater.from(context);
        this.mItems = objects;
    }

    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public LWNModel_message getItem(int position) {
        return mItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LWNModel_message item = getItem(position);
        List<String> imgList= item.getArray_image();
        bitmapUtils=new BitmapUtils(context_this);
        String[] string_location = {"北京", "上海", "天津", "重庆", "黑龙江省", "吉林省", "辽宁省", "河北省", "山西省", "内蒙古", "山东省",
                "安徽省", "江苏省", "浙江省", "江西省", "福建省", "河南省", "湖北省", "湖南省", "广东省", "广西", "海南省", "四川省", "贵州省", "云南省", "西藏", "陕西省", "甘肃省", "青海省", "宁夏", "新疆",
                "香港", "澳门", "台湾省"};

        int kind_content = Integer.parseInt(item.getQuestion_type());
        String location = string_location[Integer.parseInt(item.getQuestion_area())];
        int flag = item.getFlag();
        int unread = Integer.parseInt(item.getIsunread());
        View_content view_content = null;
        View_rating view_rating = null;

        if (convertView == null) {
            if (flag == 0) {
                view_content=new View_content();
                convertView = mInflater.inflate(R.layout.item_mc_dongtai, null);
                view_content = new View_content();
                view_content.item_name = (TextView) convertView.findViewById(R.id.item_mcdongtai_name);
                view_content.item_lingyu = (TextView) convertView.findViewById(R.id.item_mcdongtai_lingyu);
                view_content.item_leixing = (TextView) convertView.findViewById(R.id.item_mcdongtai_leixing);
                view_content.item_time = (TextView) convertView.findViewById(R.id.item_mcdongtai_time);
                view_content.item_content = (TextView) convertView.findViewById(R.id.item_mcdongtai_content);
                view_content.imageView_unread = (ImageView) convertView.findViewById(R.id.dongtai_newmessage);
                view_content.line_image= (LinearLayout) convertView.findViewById(R.id.line_image);
                view_content.item_imageone= (ImageView) convertView.findViewById(R.id.item_imageone);
                view_content.item_imagetwo= (ImageView) convertView.findViewById(R.id.item_imagetwo);
               // convertView.setTag(R.layout.item_mc_dongtai);
                convertView.setTag(view_content);
            } else {
                view_rating=new View_rating();
                convertView = mInflater.inflate(R.layout.item_mc_dongtairating,null);
                view_rating = new View_rating();
                view_rating.item_name = (TextView) convertView.findViewById(R.id.item_mcdongtai_name);
                view_rating.item_lingyu = (TextView) convertView.findViewById(R.id.item_mcdongtai_lingyu);
                view_rating.item_leixing = (TextView) convertView.findViewById(R.id.item_mcdongtai_leixing);
                view_rating.item_time = (TextView) convertView.findViewById(R.id.item_mcdongtai_time);
                view_rating.item_content = (TextView) convertView.findViewById(R.id.item_mcdongtai_content);
                view_rating.imageView_unread = (ImageView) convertView.findViewById(R.id.dongtai_newmessage);
                view_rating.textView_fw = (TextView) convertView.findViewById(R.id.dongtai_fw);
                view_rating.textView_zy = (TextView) convertView.findViewById(R.id.dongtai_zy);
                view_rating.textView_xy = (TextView) convertView.findViewById(R.id.dongtai_xy);
                view_rating.rating_fw = (RatingBar) convertView.findViewById(R.id.item_mc_fw);
                view_rating.rating_zy = (RatingBar) convertView.findViewById(R.id.item_mc_zy);
                view_rating.rating_xy = (RatingBar) convertView.findViewById(R.id.item_mc_xy);
                convertView.setTag(view_rating);
            }
        } else {
            if (flag == 0) {
                view_content = (View_content) convertView.getTag(R.layout.item_mc_dongtai);
                if (view_content == null) {
                    convertView = mInflater.inflate(R.layout.item_mc_dongtai, null);
                    view_content = new View_content();
                    view_content.item_name = (TextView) convertView.findViewById(R.id.item_mcdongtai_name);
                    view_content.item_lingyu = (TextView) convertView.findViewById(R.id.item_mcdongtai_lingyu);
                    view_content.item_leixing = (TextView) convertView.findViewById(R.id.item_mcdongtai_leixing);
                    view_content.item_time = (TextView) convertView.findViewById(R.id.item_mcdongtai_time);
                    view_content.item_content = (TextView) convertView.findViewById(R.id.item_mcdongtai_content);
                    view_content.imageView_unread = (ImageView) convertView.findViewById(R.id.dongtai_newmessage);
                    view_content.line_image= (LinearLayout) convertView.findViewById(R.id.line_image);
                    view_content.item_imageone= (ImageView) convertView.findViewById(R.id.item_imageone);
                    view_content.item_imagetwo= (ImageView) convertView.findViewById(R.id.item_imagetwo);
                    convertView.setTag(R.layout.item_mc_dongtai, view_content);
                }
            } else {
                view_rating = (View_rating) convertView.getTag(R.layout.item_mc_dongtairating);
                if (view_rating == null) {
                    convertView = mInflater.inflate(R.layout.item_mc_dongtairating, null);
                    view_rating = new View_rating();
                    view_rating.item_name = (TextView) convertView.findViewById(R.id.item_mcdongtai_name);
                    view_rating.item_lingyu = (TextView) convertView.findViewById(R.id.item_mcdongtai_lingyu);
                    view_rating.item_leixing = (TextView) convertView.findViewById(R.id.item_mcdongtai_leixing);
                    view_rating.item_time = (TextView) convertView.findViewById(R.id.item_mcdongtai_time);
                    view_rating.item_content = (TextView) convertView.findViewById(R.id.item_mcdongtai_content);
                    view_rating.imageView_unread = (ImageView) convertView.findViewById(R.id.dongtai_newmessage);
                    view_rating.textView_fw = (TextView) convertView.findViewById(R.id.dongtai_fw);
                    view_rating.textView_zy = (TextView) convertView.findViewById(R.id.dongtai_zy);
                    view_rating.textView_xy = (TextView) convertView.findViewById(R.id.dongtai_xy);
                    view_rating.rating_fw = (RatingBar)convertView.findViewById(R.id.item_mc_fw);
                    view_rating.rating_zy = (RatingBar)convertView.findViewById(R.id.item_mc_zy);
                    view_rating.rating_xy = (RatingBar)convertView.findViewById(R.id.item_mc_xy);
                    convertView.setTag(R.layout.item_mc_dongtairating, view_rating);
                }
            }
        }

        //设置数据
        if (flag == 0) {
            if(imgList!=null&&imgList.size()>0){
                view_content.line_image.setVisibility(View.VISIBLE);
                for(int i=0;i<imgList.size();i++){
                    bitmapUtils.display( view_content.line_image.getChildAt(i),imgList.get(i));
                }
            }else{
                view_content.line_image.setVisibility(View.GONE);
            }
            if (kind_content < 10) {
                view_content.item_leixing.setText("个人问题");
            } else {
                view_content.item_leixing.setText("公司问题");
            }
            view_content.item_name.setText(location + "网友" + "  追问了你");
            switch (kind_content) {
                case 0: {
                    view_content.item_lingyu.setText("婚姻家庭");
                }
                break;
                case 1: {
                    view_content.item_lingyu.setText("房屋买卖");
                }
                break;
                case 2: {
                    view_content.item_lingyu.setText("债务纠纷");
                }
                break;
                case 3: {
                    view_content.item_lingyu.setText("劳动争议");
                }
                break;
                case 4: {
                    view_content.item_lingyu.setText("交通肇事");
                }
                break;
                case 5: {
                    view_content.item_lingyu.setText("刑事案件");
                }
                break;
                case 6: {
                    view_content.item_lingyu.setText("其他类型");
                }
                break;
                case 11: {
                    view_content.item_lingyu.setText("公司注册");
                }
                break;
                case 12: {
                    view_content.item_lingyu.setText("投资融资");
                }
                break;
                case 13: {
                    view_content.item_lingyu.setText("股权期权");
                }
                break;
                case 14: {
                    view_content.item_lingyu.setText("合同事项");
                }
                break;
                case 15: {
                    view_content.item_lingyu.setText("知识产权");
                }
                break;
                case 16: {
                    view_content.item_lingyu.setText("财税事务");
                }
                break;
                case 17: {
                    view_content.item_lingyu.setText("劳动人事");
                }
                break;
                case 18: {
                    view_content.item_lingyu.setText("债务纠纷");
                }
                break;
                case 19: {
                    view_content.item_lingyu.setText("其他问题");
                }
                break;
                default:
                    break;
            }
            if(item.getContent().equals("")||item.getContent()==null){
                view_content.item_content.setVisibility(View.GONE);
            }else{
                view_content.item_content.setVisibility(View.VISIBLE);
                view_content.item_content.setText(item.getContent());
            }

            view_content.item_time.setText(item.getTime());
            if(unread == 0){
                view_content.imageView_unread.setVisibility(View.GONE);
                view_content.item_content.setTextColor(Color.rgb(169, 169, 169));
            }
            else{
                view_content.imageView_unread.setVisibility(View.VISIBLE);
                view_content.item_content.setTextColor(Color.rgb(121, 121, 121));
            }

        } else {
            if (kind_content < 10) {
                view_rating.item_leixing.setText("个人问题");
            } else {
                view_rating.item_leixing.setText("公司问题");
            }
            view_rating.item_name.setText(location + "网友" + "  评价了你");

            switch (kind_content) {
                case 0: {
                    view_rating.item_lingyu.setText("婚姻家庭");
                }
                break;
                case 1: {
                    view_rating.item_lingyu.setText("房屋买卖");
                }
                break;
                case 2: {
                    view_rating.item_lingyu.setText("债务纠纷");
                }
                break;
                case 3: {
                    view_rating.item_lingyu.setText("劳动争议");
                }
                break;
                case 4: {
                    view_rating.item_lingyu.setText("交通肇事");
                }
                break;
                case 5: {
                    view_rating.item_lingyu.setText("刑事案件");
                }
                break;
                case 6: {
                    view_rating.item_lingyu.setText("其他类型");
                }
                break;
                case 11: {
                    view_rating.item_lingyu.setText("公司注册");
                }
                break;
                case 12: {
                    view_rating.item_lingyu.setText("投资融资");
                }
                break;
                case 13: {
                    view_rating.item_lingyu.setText("股权期权");
                }
                break;
                case 14: {
                    view_rating.item_lingyu.setText("合同事项");
                }
                break;
                case 15: {
                    view_rating.item_lingyu.setText("知识产权");
                }
                break;
                case 16: {
                    view_rating.item_lingyu.setText("财税事务");
                }
                break;
                case 17: {
                    view_rating.item_lingyu.setText("劳动人事");
                }
                break;
                case 18: {
                    view_rating.item_lingyu.setText("债务纠纷");
                }
                break;
                case 19: {
                    view_rating.item_lingyu.setText("其他问题");
                }
                break;
                default:
                    break;
            }
            view_rating.item_content.setText(item.getContent());
            view_rating.item_time.setText(item.getTime());
            if (unread == 0) {
                view_rating.imageView_unread.setVisibility(View.GONE);
                view_rating.textView_fw.setTextColor(Color.rgb(169, 169, 169));
                view_rating.textView_xy.setTextColor(Color.rgb(169, 169, 169));
                view_rating.textView_zy.setTextColor(Color.rgb(169, 169, 169));
                view_rating.item_content.setTextColor(Color.rgb(169, 169, 169));

            } else {
                view_rating.imageView_unread.setVisibility(View.VISIBLE);
                view_rating.textView_fw.setTextColor(Color.rgb(121, 121, 121));
                view_rating.textView_xy.setTextColor(Color.rgb(121, 121, 121));
                view_rating.textView_zy.setTextColor(Color.rgb(121, 121, 121));
                view_rating.item_content.setTextColor(Color.rgb(121, 121, 121));

            }

//            view_rating.textView_fw.setText("服务态度:");
//            view_rating.textView_xy.setText("响应速度:");
//            view_rating.textView_xy.setText("专业程度:");

            view_rating.rating_xy.setRating(Float.parseFloat(item.getXy_fraction()));
            view_rating.rating_fw.setRating(Float.parseFloat(item.getFw_fraction()));
            view_rating.rating_zy.setRating(Float.parseFloat(item.getZy_fraction()));
        }
        return convertView;
    }

    class View_content {
        private TextView item_name;
        private TextView item_lingyu;
        private TextView item_content;
        private TextView item_time;
        private TextView item_leixing;
        private ImageView imageView_unread;
        private LinearLayout line_image;
        private ImageView item_imageone;
        private ImageView item_imagetwo;
    }

    class View_rating {
        private TextView item_name;
        private TextView item_lingyu;
        private TextView item_content;
        private TextView item_time;
        private TextView item_leixing;
        private ImageView imageView_unread;
        private TextView textView_xy;
        private RatingBar rating_xy;
        private TextView textView_fw;
        private RatingBar rating_fw;
        private TextView textView_zy;
        private RatingBar rating_zy;
    }
}
